<?php
declare(strict_types=1);

namespace traits;

use of;
use L;

trait SystemTrait
{
    //根据SKU的后缀获取到属于哪一个团队
    public static function belong($sku)
    {
        $skuCode = explode("-", $sku);
        $tail = $skuCode[(count($skuCode) - 1)];
        switch ($tail) {
            case '01':
                $belong = 1;
                break;
            case '02':
                $belong = 2;
                break;
            case '03':
                $belong = 3;
                break;
            case '04':
                $belong = 4;
                break;
            case '05':
                $belong = 5;
                break;
            case '06':
                $belong = 6;
                break;
            case '07':
                $belong = 7;
                break;
            case '08':
                $belong = 8;
                break;
            case '09':
                $belong = 9;
                break;
            case '10':
                $belong = 10;
                break;
            case '11':
                $belong = 11;
                break;
            case '12':
                $belong = 12;
                break;
            case '13':
                $belong = 13;
                break;
            case '14':
                $belong = 14;
                break;
            case '15':
                $belong = 15;
                break;
            default:
                $belong = of::config('env.PUBLIC_BELONG');
                break;
        }

        return $belong;
    }

    //给相应的运营团队加上后缀
    public static function tail($belong): string
    {
        switch ($belong) {
            case 1:
                $tail = '-01';
                break;
            case 2:
                $tail = '-02';
                break;
            case 3:
                $tail = '-03';
                break;
            case 4:
                $tail = '-04';
                break;
            case 5:
                $tail = '-05';
                break;
            case 6:
                $tail = '-06';
                break;
            case 7:
                $tail = '-07';
                break;
            case 8:
                $tail = '-08';
                break;
            case 9:
                $tail = '-09';
                break;
            case 10:
                $tail = '-10';
                break;
            case 11:
                $tail = '-11';
                break;
            case 12:
                $tail = '-12';
                break;
            case 13:
                $tail = '-13';
                break;
            case 14:
                $tail = '-14';
                break;
            case 15:
                $tail = '-15';
                break;
            default:
                $tail = '-00';
                break;
        }
        return $tail;
    }

    //获取配置信息
    public static function confing($name)
    {
        $sql = "SELECT * FROM config WHERE 1 AND `name` = '{$name}';";
        $result = L::sql($sql);
        $data = [];
        if (!empty($result)) {
            $rows = json_decode($result[0]['values'], true);
            foreach ($rows as $v) {
                $data[$v['label']] = $v['value'];
            }
        }

        return $data;
    }



}